package chapter05;

import java.util.Calendar;
import java.util.Date;

public class Java07_Object_Date_Test {
    public static void main(String[] args) {
        // TODO 打印当前日历
        System.out.println("周一\t周二\t周三\t周四\t周五\t周六\t周日");
        // 获取当前日历对象
        Calendar firstDate = Calendar.getInstance();
        // 将日历对象设定位当前月第一天
        firstDate.set(Calendar.DAY_OF_MONTH, 1);
        // 获取当前月最大日期
        int maxDay = firstDate.getMaximum(Calendar.DAY_OF_MONTH);

        for (int i = 0; i <= maxDay; i++) {
            // 当前日期是周几
            int weekX = firstDate.get(Calendar.DAY_OF_WEEK);
            // 当前日期是几号
            int montY = firstDate.get(Calendar.DAY_OF_MONTH);
            if ( i == 0 ) {
                if ( weekX == Calendar.SUNDAY) {
                    for (int j = 0; j < 6; j++) {
                        System.out.print("\t");
                    }
                    System.out.println(montY);
                } else {
                    // 周日是1.周一是2.....周六是7
                    for (int j = 0; j < weekX-2; j++) {
                        System.out.print("\t");
                    }
                    System.out.print(montY);
                    System.out.print("\t");
                }

            } else {
                // 不是一号,判断是否为周日
                if ( weekX == Calendar.SUNDAY) {
                    System.out.println(montY);
                } else {
                    System.out.print(montY);
                    System.out.print("\t");
                }
            }
            // 打印日历后增加一天
            firstDate.add(Calendar.DATE,1);
        }
    }
}

